import axios from "axios";
import { ElMessage } from 'element-plus';
 const httpClient = axios.create({
   baseURL: import.meta.env.VITE_API_BASE, // 替换为你的后端API地址
  // baseURL: 'http://localhost:8080', // 替换为你的后端API地址
   timeout: 5000,
});
httpClient.interceptors.request.use(
  (config) => {
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);
httpClient.interceptors.response.use(
  (response) => {
    console.log(response);
    const { code, message } = response.data;
    if (code === 200) {
      return response.data.data;
    } else {
      // 这里可以添加错误处理逻辑，例如弹窗提示错误信息
      ElMessage.error(message || 'Error');
      return Promise.reject(new Error(message || 'Error'));
    }
  },
  (error) => {
    ElMessage.error(error.message);
    return Promise.reject(error);
  }
);
export default httpClient